
<template>
  <app-layout viewName="crm_leadlistview9" viewTitle="线索/商机列表视图" :className="{ 'view-container': true, 'default-mode-view': true, 'delistview9': true, 'crm-lead-list-view9': true }" layoutMode="VIEW" :isShowUserInfo="isDefaultView()" :openMode="openMode" @close-view="closeView($event)">
    <template slot="headerLeft">
      <div class="view-header-left">

        <div class="view-caption" v-if="isDefaultView()">{{$t(model.srfCaption)}}</div>
        <modal-breadcrumb v-if="isModalView()"/>
      </div>
    </template>
    <template slot="headerRight">
      <div class="view-header-right">
        <app-header-menus :toolbarModel="toolBarModels" @menu-click="toolbar_click($event)" mode="view" :openMode="openMode" :isEnableQuickSearch="true" searchPlaceholder="请输入商机" v-model="query" @search="onSearch($event)"/>
      </div>
    </template>
    <template slot="content">
      <div class="view-content-wrapper">
        
<view_list 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context" 
    createAction="Create"
    removeAction="Remove"
    updateAction="Update"
    fetchAction="FetchDefault"
    :showBusyIndicator="true"
    name="list"  
    ref='list' 
    @selectionchange="list_selectionchange($event)"  
    @beforeload="list_beforeload($event)"  
    @rowdblclick="list_rowdblclick($event)"  
    @remove="list_remove($event)"  
    @load="list_load($event)"  
    @closeview="closeView($event)">
</view_list>


      </div>
    </template>
  </app-layout>
</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { UIActionTool, Util } from '@/utils';
import { VueLifeCycleProcessing, ListView9Base } from '@/crm-core';
import Crm_leadService from '@/service/crm-lead/crm-lead-service';

import ListView9Engine from '@engine/view/list-view9-engine';


/**
 * 线索/商机列表视图基类
 *
 * @export
 * @class Crm_leadListView9Base
 * @extends {ListView9Base}
 */
@Component({})
@VueLifeCycleProcessing
export default class Crm_leadListView9Base extends ListView9Base {

    /**
     * 实体服务对象
     *
     * @type {Crm_leadService}
     * @memberof Crm_leadListView9Base
     */
    public appEntityService: Crm_leadService = new Crm_leadService;

    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof Crm_leadListView9Base
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof Crm_leadListView9Base
	 */
	public viewtag: string = '954f317c0e57e62054d889a707a1cb83';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof Crm_leadListView9Base
     */
    protected srfparentdata: any = {};

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof Crm_leadListView9Base
	 */
    protected customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof Crm_leadListView9Base
	 */
    protected customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof Crm_leadListView9Base
     */
    public model: any = {
        srfCaption: 'entities.crm_lead.views.listview9.caption',
        srfTitle: 'entities.crm_lead.views.listview9.title',
        srfSubTitle: 'entities.crm_lead.views.listview9.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof Crm_leadListView9Base
     */
    public containerModel: any = {
        view_toolbar: { name: 'toolbar', type: 'TOOLBAR' },
        view_list: { name: 'list', type: 'LIST' },
    };

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof Crm_leadListView9Base
     */
    public viewState: Subject<ViewState> = new Subject();

    /**
     * 工具栏模型
     *
     * @type {*}
     * @memberof Crm_leadListView9
     */
    public toolBarModels: any = {
    };



    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof Crm_leadListView9Base
     */
    public engine: ListView9Engine = new ListView9Engine();
	

    /**
     * 引擎初始化
     *
     * @public
     * @memberof Crm_leadListView9Base
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            list: this.$refs.list,
            opendata: (args: any[], params?: any, $event?: any, xData?: any) => {
                this.opendata(args, params, $event, xData);
            },
            newdata: (args: any[], params?: any, $event?: any, xData?: any) => {
                this.newdata(args, params, $event, xData);
            },
            keyPSDEField: 'crm_lead',
            majorPSDEField: 'name',
            isLoadDefault: true,
        });
    }


    /**
     * list 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadListView9Base
     */
    public list_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('list', 'selectionchange', $event);
    }


    /**
     * list 部件 beforeload 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadListView9Base
     */
    public list_beforeload($event: any, $event2?: any) {
        this.engine.onCtrlEvent('list', 'beforeload', $event);
    }


    /**
     * list 部件 rowdblclick 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadListView9Base
     */
    public list_rowdblclick($event: any, $event2?: any) {
        this.engine.onCtrlEvent('list', 'rowdblclick', $event);
    }


    /**
     * list 部件 remove 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadListView9Base
     */
    public list_remove($event: any, $event2?: any) {
        this.engine.onCtrlEvent('list', 'remove', $event);
    }


    /**
     * list 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadListView9Base
     */
    public list_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('list', 'load', $event);
    }



    /**
     * 打开新建数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof Crm_leadListView9
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
        const data: any = {};
        let curViewParam = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(curViewParam,args[0]);
        }
        let deResParameters: any[] = [];
        if(curViewParam.res_partner && true){
            deResParameters = [
            { pathName: 'res_partners', parameterName: 'res_partner' },
            ]
        }
        const parameters: any[] = [
            { pathName: 'crm_leads', parameterName: 'crm_lead' },
        ];
        const _this: any = this;
        const openPopupModal = (view: any, data: any) => {
            let container: Subject<any> = this.$appmodal.openModal(view, curViewParam, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: 'crm-lead-edit-view', 
            height: 0, 
            width: 0,  
            title: this.$t('entities.crm_lead.views.editview.title'),
        };
        openPopupModal(view, data);
    }


    /**
     * 打开编辑数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof Crm_leadListView9
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) {
        const data: any = {};
        let curViewParam = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(curViewParam,args[0]);
        }
        let deResParameters: any[] = [];
        if(curViewParam.res_partner && true){
            deResParameters = [
            { pathName: 'res_partners', parameterName: 'res_partner' },
            ]
        }
        const parameters: any[] = [
            { pathName: 'crm_leads', parameterName: 'crm_lead' },
        ];
        const _this: any = this;
        const openPopupModal = (view: any, data: any) => {
            let container: Subject<any> = this.$appmodal.openModal(view, curViewParam, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: 'crm-lead-edit-view', 
            height: 0, 
            width: 0,  
            title: this.$t('entities.crm_lead.views.editview.title'),
        };
        openPopupModal(view, data);
    }




    /**
     * 销毁视图回调
     *
     * @memberof Crm_leadListView9Base
     */
    public destroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
        }
    }
    /**
     * 搜索值
     *
     * @type {string}
     * @memberof Crm_leadListView9
     */
    public query: string = '';

    /**
     * 是否展开搜索表单
     *
     * @type {boolean}
     * @memberof Crm_leadListView9
     */
    public isExpandSearchForm: boolean = false;

    /**
     * 快速搜索
     *
     * @param {*} $event
     * @memberof Crm_leadListView9
     */
    public onSearch($event: any): void {
        const refs: any = this.$refs;
        if (refs.list) {
            refs.list.load({});
        }
    }

}
</script>

<style lang='less'>
@import './crm-lead-list-view9.less';
</style>